/* 
 * File:   main.cpp
 * Author: johnneyshi
 *
 * Created on 2013年1月26日, 下午1:08
 */

#include <cstdlib>
#include "JServer.h"
#include "JServerMaster.h"
#include "JException.h"
#include <iostream>
#include "JClient.h"
#include <string.h>
#include <sys/epoll.h>
#include <fcntl.h>

using namespace std;

class MyServer : public JServer
{
public:
    MyServer(std::string _ip,int port) : JServer(_ip,port)
    {
        
    }
    virtual void DealEpollFd(int fd)
    {
        char buff[10];
        bzero(buff,10);
        int n = -1;
        while((n = read(fd,buff,10)) > 0)
        {
            cout << n << ":" << buff << endl;
            bzero(buff,10);
        }
        cout << endl << "end" << endl;
    }
    virtual void DealNewConnfd(int newFd)
    {
        int flag = fcntl(newFd,F_GETFL,0);
        //fcntl(newFd,F_SETFL, flag | O_NONBLOCK);
        struct epoll_event ev;
        ev.events = EPOLLIN | EPOLLET;
        ev.data.fd = newFd;
        if(epoll_ctl(this->epollHandler,EPOLL_CTL_ADD,newFd,&ev) < 0)
        {
            
        }
    }
};

int main(int argc, char** argv) {
    MyServer server("127.0.0.1",4000);
    server.Start();
    return 0;
}

/*
 * 
 */
//int main(int argc, char** argv) 
//{
//    try
//    {
////        JServerMaster master;
////        master.Init("/home/johnneyshi/Projects/CPlusPlus/Console/JAll/JServerMaster/config.xml");
////        master.Start();
////        JBuffer buff;
////        buff.Put("aaaaaaaaa",9);
////        for(int i = 0;i < 15; ++i)
////        {
////            buff.Put("h",1);
////        }
////        
////        char cc[100];
////        int tmp = 100;
////        buff.Get(cc,tmp);
////        cc[tmp] = '\0';
////        cout << cc << endl;
////        char c[12];
////        int tmp = 15;
////        cout << buff.Get(c,tmp) << endl;
////        cout << tmp << endl;
////        c[11] = '\0';
////        cout << c << endl;
//        
//        
//        
//        //master.ReadConfig("/home/johnneyshi/Projects/CPlusPlus/Console/JServerMaster/config.xml");
////        string ip;
////        int port;
////        cout << "ip:";
////        cin >> ip;
////        cout << endl << "port:";
////        cin >> port;
////        JServerMaster master(ip,port);
////        //master.Start();
////        while(true)
////        {
////            string ip2;
////            int port2;
////            cout << "ip:";
////            cin >> ip2;
////            cout << endl << "port:";
////            cin >> port2;
////            master.AddWorker(ip2,port2);
////        }
//    }catch(JException& e)
//    {
//        cout << e.GetMessage() << endl;
//    }
//    return 0;
//}
//
